package com.tf.temper.controller;

import com.ccssoft.m8.common.web.BaseController;
import com.tf.temper.entity.DeviceReturnEntity;
import com.tf.temper.entity.FeedbackresultlistEntity;
import com.tf.temper.entity.LogfeedbackEntity;
import com.tf.temper.service.LogfeedbackService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 上传反馈记录接口
 * @author allen
 * @date: 2020年9月14日上午10:56:20
 */
@Api(value = "上传反馈记录接口",description="DeviceuploadController")
@RestController
@RequestMapping("/syresult")
public class DeviceuploadController extends BaseController
{
    @Autowired
    private LogfeedbackService<LogfeedbackEntity> logfeedbackService;
    @ApiOperation("上传反馈记录接口")
    @PostMapping("/{deviceid}")
    @CrossOrigin(origins = "*",maxAge = 86400)
    public DeviceReturnEntity<String> syresult(@PathVariable("deviceid") String deviceid, @RequestBody FeedbackresultlistEntity feedbackentity)
    {
        if(feedbackentity!=null)
        {
            if(feedbackentity.getResultList()!=null&&deviceid!=null)
            {
                LogfeedbackEntity logfdenty = new LogfeedbackEntity();
                logfdenty.setDeviceid(deviceid);
                logfdenty.setUserid(feedbackentity.getResultList().getUserID());
                logfdenty.setMsg(feedbackentity.getResultList().getMsg());
                logfdenty.setStatus(feedbackentity.getResultList().getStatus());
                logfdenty.setOperationtype(feedbackentity.getResultList().getOperationType());
                logfeedbackService.insert(logfdenty);
                return new DeviceReturnEntity<String>().ok("0");
            }
        }
        return  new DeviceReturnEntity<String>().error("RequestBody is empty");
    }
}